C++题目:char s[]={'h','e','l','l','o'}; strlen(s)值为?
来源:百度知道 编辑:UC知道 时间:2024/05/27 14:39:59
他的值应该是不确定的,因为你没有在字符串s中加入字符串结束符,如果你在初始化s时变为char s[]={'h','e','l','l','o','\0'}; 那么,他的值应该就是5.
#include <iostream.h>
#include <string>
void main()
{
char s[] = {'h','e','l','l','o'};
int a = strlen(s); //值为 11
int b = sizeof(s); //值为 5
cout <<a <<b;
}
那个值是不确定的值,运气好的话可能是5(概率非常低),一般情况是大于5的,要能得到确定的值,得这样改:char s[] = {'h', 'e', 'l', 'l', 'o', '\0'};
长度不确定,因为strlen求长度以\0为结尾,这里没有结尾符号,所以长度违法确定
不知道,因为没有'\0'字符串长度无法计算
5
C语言的 char s[]="Program",*p=s; 是什么意思?
char *s = "china";等价于 char *s;s = "china";对不对?
char s[]="ABCD";
char *p = "baidu"; *p = 's';这段程序可以在turbo c下运行无错,但是在vc上会有内存错。为什么?
编写函数void fun(char s[],int c)
c语言的题目struct STU {char num[10];
数组 char s[ ]="abc"有几个元素
!!!!!!!!急急急:怎么把char ch= 'ab' 转化成 AB??(C++)
C++:cannot convert from 'char [9]' to 'char [20]'
c语言 char* 问题